<?php
include($_SERVER["DOCUMENT_ROOT"] . "/model/base_function.php");

function model_get_aboutus_list()
{
	$aboutus_list = array();
	$connection = connect_to_database();

	$query_string = "select * from aboutus";

	$query_string = $query_string . " ORDER BY id";

	$result = mysql_query($query_string, $connection);

	while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
	{
		$aboutus = $row;
		$aboutus["detail_view_url"] = "list.php?id=" . $aboutus["id"]; 
		$aboutus_list[] = $aboutus;
	}
	
	mysql_close($connection);
	return $aboutus_list;
}

function model_get_aboutus_details($aboutus_id)
{
	$aboutus_details = array();
	$connection = connect_to_database();

	$query_string = "select * from aboutus where id = " . $aboutus_id;
	$result = mysql_query($query_string, $connection);
	if (!$result)
	{
		return;
	}

	$aboutus_details = mysql_fetch_array($result, MYSQL_ASSOC);
	mysql_free_result($result);

	mysql_close($connection);
	return $aboutus_details;
}

function model_update_aboutus_clickcount($aboutus_id)
{
	$connection = connect_to_database();

	$query_string =
	"UPDATE aboutus SET click_count = click_count + 1 WHERE id = " . $aboutus_id;
	if (mysql_query($query_string, $connection) == true)
	{
		mysql_close($connection);
		return true;
	}
	else
	{
		mysql_close($connection);
		return false;
	}
}

function model_insert_aboutus($aboutus)
{
	$connection = connect_to_database();

	// sql for upload aboutus
	$query_string =
	"INSERT
		INTO aboutus
		SET
			name = \"". mysql_real_escape_string($aboutus["name"], $connection)  ."\",
			details = \"" . mysql_real_escape_string($aboutus["details"], $connection) . "\",
			publish_time = NOW();";

	$result = mysql_query($query_string, $connection);
	if ($result == NULL)
	{
		print(mysql_error());
		mysql_close($connection);
		return false;
	}

	mysql_close($connection);
	return true;
}

function model_delete_aboutus($id)
{
	$aboutus_details = array();
	$connection = connect_to_database();

	$query_string = "DELETE FROM aboutus where id = " . $id;
	if (mysql_query($query_string, $connection) == true)
	{
		mysql_close($connection);
		return true;
	}
	else
	{
		mysql_close($connection);
		return false;
	}
}

function model_update_aboutus($id, $aboutus)
{
	$connection = connect_to_database();

	// sql for upload aboutus
	$query_string =
	"UPDATE aboutus
		SET
			name = \"". mysql_real_escape_string($aboutus["name"], $connection)  ."\",
			details = \"" . mysql_real_escape_string($aboutus["details"], $connection) . "\",
			publish_time = NOW()
		WHERE id = " . $aboutus["id"];

	$result = mysql_query($query_string, $connection);
	if ($result == NULL)
	{
		print(mysql_error());
		mysql_close($connection);
		return false;
	}

	mysql_close($connection);
	return true;
}
?>
